package com.search.tools;

import java.util.Random;

public class UUIDGeneratorTool {
    private static final String CHARS = "0123456789abcdef";
    private static final Random random = new Random();

    public static String wxuuid() {
        char[] uuid = new char[36];

        for (int i = 0; i < 36; i++) {
            int index = random.nextInt(16); // 生成0到15之间的随机数
            uuid[i] = CHARS.charAt(index);
        }

        // 设置第15位为'4'
        uuid[14] = '4';

        // 设置第20位，这里先随机一个数，然后通过位运算确定最终字符
        int temp = CHARS.indexOf(uuid[19]) & 3 | 8;
        uuid[19] = CHARS.charAt(temp);

        // 在指定位置插入'-'
        uuid[8] = '-';
        uuid[13] = '-';
        uuid[18] = '-';
        uuid[23] = '-';

        return new String(uuid);
    }
}
